package com.ruoyi.parcel.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.parcel.service.IEAdvertisementsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.parcel.domain.EAdvertisements;
import com.ruoyi.parcel.service.IEAdvertisementsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * parcelController
 *
 * @author ruoyi
 * @date 2024-11-28
 */
@RestController
@RequestMapping("/EAdvertisements")
public class EAdvertisementsController extends BaseController
{
    @Autowired
    private IEAdvertisementsService eAdvertisementsService;

    /**
     * 查询parcel列表
     */
    @RequiresPermissions("parcel:EAdvertisements:list")
    @GetMapping("/list")
    public TableDataInfo list(EAdvertisements eAdvertisements)
    {
        startPage();
        List<EAdvertisements> list = eAdvertisementsService.selectEAdvertisementsList(eAdvertisements);
        return getDataTable(list);
    }

    /**
     * 导出parcel列表
     */
    @RequiresPermissions("parcel:EAdvertisements:export")
    @Log(title = "parcel", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EAdvertisements eAdvertisements)
    {
        List<EAdvertisements> list = eAdvertisementsService.selectEAdvertisementsList(eAdvertisements);
        ExcelUtil<EAdvertisements> util = new ExcelUtil<EAdvertisements>(EAdvertisements.class);
        util.exportExcel(response, list, "parcel数据");
    }

    /**
     * 获取parcel详细信息
     */
    @RequiresPermissions("parcel:EAdvertisements:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(eAdvertisementsService.selectEAdvertisementsById(id));
    }

    /**
     * 新增parcel
     */
    @RequiresPermissions("parcel:EAdvertisements:add")
    @Log(title = "parcel", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EAdvertisements eAdvertisements)
    {
        eAdvertisements.setStatus(1);
        System.out.println(eAdvertisements);
        return toAjax(eAdvertisementsService.insertEAdvertisements(eAdvertisements));
    }

    /**
     * 修改parcel
     */
    @RequiresPermissions("parcel:EAdvertisements:edit")
    @Log(title = "parcel", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EAdvertisements eAdvertisements)
    {
        return toAjax(eAdvertisementsService.updateEAdvertisements(eAdvertisements));
    }

    /**
     * 删除parcel
     */
    @RequiresPermissions("parcel:EAdvertisements:remove")
    @Log(title = "parcel", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eAdvertisementsService.deleteEAdvertisementsByIds(ids));
    }
    @Log(title = "parcel", businessType = BusinessType.DELETE)
	@PostMapping("/updateStatus/{id}")
    public void updateStatus(@PathVariable Long id)
    {
         eAdvertisementsService.updateStatus(id);
    }
}
